import {Component, Input} from '@angular/core';
import {FormsModule} from "@angular/forms";
import {NgIf, UpperCasePipe} from "@angular/common";
import {Hero} from '../hero';
import {HeroService} from "../hero.service";
import {ActivatedRoute, RouterLink} from "@angular/router";
import {routes} from "../app-routing.module";

@Component({
  selector: 'app-hero-detail',
  standalone: true,
  imports: [
    FormsModule,
    NgIf,
    UpperCasePipe,
    RouterLink
  ],
  templateUrl: './hero-detail.component.html',
  styleUrl: './hero-detail.component.css'
})
export class HeroDetailComponent {
  hero?: Hero;

  goBack(): void {
  }

  resUrl: string = ""

  ngOnInit(): void {
    this.getHero();
  }

  getHero(): void {
    const id = Number(this.route.snapshot.paramMap.get('id'));
    this.heroService.getHero(id)
      .subscribe(hero => this.hero = hero);
  }

  constructor(
    private route: ActivatedRoute,
    private heroService: HeroService,
  ) {
    this.route.url.subscribe(url => {
      console.log('Previous URL:', url);
    });
  }


}
